<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Home\Controller;
use Think\Controller;
use Admin\Model\UserModel;
use Admin\Model\IntegralModel;
/**
 * Description of TimeController
 *
 * @author Administrator
 */
class TimeController extends Controller {
    //put your code here
    private $userModel;
    private $integralModel;
    function __construct() {
        parent::__construct();
        $this->userModel = new UserModel();
        $this->integralModel = new IntegralModel();
    }
    
    public function index(){
    	$map = [
    		'type' => ['eq', 3],
    		'ctime' => ['gt', strtotime(date('Ymd'))]
    	];

        if($this->integralModel->where($map)->find()){
          exit('the task has done.');     
        }

        $list = $this->userModel->getUserReturnIntegral();
        $integralData = [];
        foreach($list as $k=>$v){
            //每个用户每天返还积分
            $incIntegral =  ( $v['return_integral'] / 100 )* C('percent') ;
            $this->userModel->increaseIntegral( $v['id'], $incIntegral);
            $integralData[] = [
                'uid'=>$v['id'],
                'integral' => $incIntegral,
                'ctime' => time(),
                'status' => 1,
                'mark' => '每日返回积分百分之'.C('percent'),
                'type' => 3
            ];
            
        }
        $this->integralModel->addAll($integralData);

        echo 'ok';
    }
}
